﻿/**
 * Created by Administrator on 2017/9/6.
 *私客转私客
 */
define(['jquery','api'],function ($,api) {
    var StopTrack = {
        name: 'stop-track',
        template: ''
        + '<Modal title="断开跟踪"'
        + '       v-model="showStopTrack"'
        + '       width="360"'
        + '       ok-text="确认"'
        + '       v-on:on-cancel="closeShift"'
        + '       v-on:on-ok="stopTrack"'
        + '       v-bind:loading="true"'
        + '       v-bind:closable="false"'
        + '       v-bind:mask-closable="false"'
        + '       class-name="turnClientWrap  vertical-center-modal stop-track-modal" ref="modal">'
        + '<div class="modal-content">'
        + ' <ul class="pri-ul">'
        + '     <li class="pri-li-txta  li-txta">'
        + '         <span class="model-left">断开原因</span>'
        + '         <p class="model-right">'
        + '             <textarea name="" v-model="stopInfo.remark"></textarea>'
        + '         </p>'
        + '     </li>'
        + '  </ul>'
        + '</div >'
        + '</Modal>',
        props: {
            type: String,
            status: String
        },
        data: function () {
            return {
                stopInfo: {
                    customerId: "",
                    remark: ""
                },
                showStopTrack: false,
            }
        },
        methods: {
            closeShift: function () {
            },
            stopTrack() {
                var thisStop = this;
                if ($.trim(thisStop.stopInfo.remark) === "") {
                    thisStop.$Message.error('断开原因不能为空');
                    thisStop.$refs.modal.buttonLoading = false;
                    return;
                }
                else
                {
                    thisStop.stopInfo.remark = $.trim(thisStop.stopInfo.remark);
                }
                api.Post_Stop_Track_Of_Customer(thisStop.stopInfo)
                    .done(function (data) {
                        if (data.IsSuccess) {
                            thisStop.$Message.success('断开成功');
                            //触发stopTrackSuccess
                            window.bus.$emit("stopTrackSuccess");
                            thisStop.showStopTrack = false;
                        } else {
                            thisStop.$Message.error(data.ErrMsg);
                            thisStop.$refs.modal.buttonLoading = false;
                        }
                    })
                    .fail(function () {
                        thisStop.$Message.error('断开失败');
                        thisStop.$refs.modal.buttonLoading = false;
                    });
            }
        },
        mounted: function () {
            var thisStop = this;
            //监听showStopTrack
            window.bus.$on("showStopTrack", function (data) {
                thisStop.stopInfo.customerId = data;
                api.Get_Track_By_Customer_And_Salesperson(thisStop.stopInfo)
                    .done(function (data) {
                        if (data.IsSuccess && data.ResultObject.length && data.ResultObject.length > 0) {
                            thisStop.showStopTrack = true;
                        } else {
                            thisStop.$Message.error("你没有在跟踪该客户");
                        }
                    })
                    .fail(function () {
                        thisStop.$Message.error('查询出错');
                    });
                //触发deleteFocus
                window.bus.$emit("deleteFocus");
            });
        },
    };
    return StopTrack;
});
